package soap.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import soap.manager.ImgInfoManager;
import soap.pojo.ImageDto;
import soap.service.ImageDtoService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Created by ZhangPY on 2021/11/17
 * Belong Organization OVERUN-9299
 * overun9299@163.com
 * Explain: ImageDtoServiceImpl
 */
@Service
public class ImageDtoServiceImpl implements ImageDtoService {

    @Autowired
    private ImgInfoManager imgInfoManager;

    @Override
    public void saveOrUpdateBatch(Set<ImageDto> imgSet) {
        Map<String, ImageDto> imageDtoMap = new HashMap<>();
        for (ImageDto imageDto : imgSet) {
            imageDtoMap.put(imageDto.getImgKey() , imageDto);
        }

        List<ImageDto> collect = imageDtoMap.entrySet().stream().map(da -> da.getValue()).collect(Collectors.toList());

        imgInfoManager.saveOrUpdateBatch(collect);

    }
}
